﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XiaoYuStock.Model.Models;

namespace XiaoYuStock.AppService.State
{
    public class CrossState : AnalysedState
    {
        public override string StateName { get { return "先跌后涨"; } }
        public override bool AnalyShareData(IEnumerable<HistoryData> historys)
        {
            bool result = false;
            var data = historys.OrderByDescending(s => s.TradeTime).ToList();
            var newData = data.FirstOrDefault();
            if (newData.CloseAmout <= 0 || newData.OpenAmount <= 0)
                return result;
            if (newData.TradeRate.HasValue && newData.TradeRate.Value>0)
            {
                if (newData.TradeRate.Value >= 3)
                {
                    data.Remove(newData);
                    var secondData = data.FirstOrDefault();
                    if (secondData.TradeRate.HasValue && secondData.TradeRate.Value < 0)
                    {
                        if (secondData.TradeRate.Value <=-3)
                        {
                            result = true;
                        }
                    }
                }

            }
           
            return result;

        }
    }

     
}
